using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace CodePlex.Resourceful.Json
{
    public class JsonArray : JsonBase, IEnumerable
    {
        private readonly List<object> _values;

        public JsonArray(JsonReader reader)
        {
            _values = ReadArrayValues(reader);
        }

        public T Get<T>(int index)
        {
            return (T)_values[index];

        }

        public IEnumerator GetEnumerator()
        {
            return _values.GetEnumerator();
        }

        private static List<object> ReadArrayValues(JsonReader reader)
        {
            reader.Read();  // startarray

            List<object> values = new List<object>();

            while (reader.TokenType != JsonToken.EndArray)
            {
                object value = ReadUnknown(reader);

                values.Add(value);

            }

            reader.Read();  // endarray

            return values;

        }



    }

}
